home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / rmhead14.zip / RMHEADER.PAS < prev    next >
Pascal/Delphi Source File  |  1994-03-14  |  5KB  |  166 lines

  1. Program RmHeader;
  2.  
  3. Uses DOS, crt, ShowRem;
  4.  
  5. Const C_Max_lines = 50;
  6.       Version = 1.4;
  7.  
  8. {These variables are used by the whole program and procedures}
  9.  
  10. Var
  11.     Max_Regels : byte;
  12.     Lines      : text;
  13.     Regels     : array[0..50] of string;
  14.     Total_Rewritten : integer;
  15.  
  16.  
  17. Procedure ReadConfig;
  18.  
  19.   Procedure Fout;
  20.   Begin
  21.     Writeln('Error : can not open RMHEADER.CFG');
  22.     Halt(1);
  23.   End; {FOUT}
  24.  
  25. Var help_counter : integer;
  26.     help_string  : string;
  27.  
  28. Begin
  29.   {Read in Config file}
  30.   Assign(Lines, 'rmheader.cfg');
  31.   {$I-}
  32.   Reset(lines);
  33.   if ioresult > 0 then fout;
  34.   {$I+}
  35.   Help_counter := 0;
  36.   Repeat
  37.    Readln(lines,help_string);
  38.    if help_string <> '' then Regels[help_counter] := help_string;
  39.    inc(help_counter);
  40.    if help_counter > C_Max_Lines then
  41.       Writeln ('Sorry, but my maximum is ',C_Max_Lines,' lines of a header.');
  42.   Until EOF(Lines) or (help_counter > C_Max_lines);
  43.   Close(lines);
  44.   Max_Regels := help_counter;
  45. end; {READCONFIG}
  46.  
  47.  
  48. Procedure Help;
  49. Begin
  50.   Writeln('Remove Header was written to remove or simplify the headers of E-mail');
  51.   Writeln('messages and news messages.');
  52.   Writeln('This program MUST find the file RMHEADER.CFG. In the file RMHEADER.CFG');
  53.   Writeln('you can write the FIRST word of a line that should be included in the');
  54.   Writeln('converted file. The word should start with a capital and end with a '':''.');
  55.   Writeln('For example Name: and Subject: are valid.');
  56.   Writeln('When using this program the command line may have wildcards.');
  57.   Writeln('This program is free to use. You use the program at your own risk.');
  58.   Writeln('If you have any problems or suggetions you can E-mail me at :');
  59.   Writeln('       C.W.G.M.ENDERS@KUB.NL');
  60.   Writeln('Or mail me at :');
  61.   Writeln('       C.W.G.M. ENDERS');
  62.   Writeln('       Professor Verbernelaan 22');
  63.   Writeln('       8016 HM  TILBURG');
  64.   Writeln('       The Netherlands');
  65.   Halt(0);
  66. END; {HELP}
  67.  
  68. Procedure Herschrijf (Filenaam : string);
  69. Const Doel = 'Doel.txt';
  70. var
  71.     FileIn, FileOut : Text;
  72.     teller, t2  : byte;
  73.     s      : string;
  74.     b      : Boolean;
  75.  
  76. Begin
  77.   {Read in the file to be converted}
  78.   if filenaam = 'RMHEADER.CFG' then exit;{skip this file}
  79.   if filenaam = 'DOEL.TXT' then exit;{skip this file}
  80.   Assign(FileIn, filenaam);
  81.   Reset(FileIn);
  82.   Assign(FileOut, doel);
  83.   Rewrite(fileout);
  84.   Teller := 0;
  85.   B:= false;
  86.   Repeat
  87.         Readln(FileIn, S);
  88.         Inc(teller);
  89.         for t2 := 0 to Max_Regels do
  90.         begin
  91.              If Pos(regels[t2],s) = 1 then
  92.              Begin
  93.                Writeln(FileOut, S);
  94.                B := TRUE;
  95.              end;{IF}
  96.         end;{FOR}
  97.   Until (S = '') or (teller > 50);
  98.   If B then { handel de doel.txt netjes af}
  99.   Begin
  100.        Writeln(fileout,s);
  101.        While not(eof(filein)) do
  102.        Begin
  103.          Readln(filein,s);
  104.          Writeln(fileout,s);
  105.        end;{WHILE}
  106.        Write (filenaam:14,'File Converted': 25);
  107.        Inc(Total_Rewritten);
  108.        Close(FileIn);
  109.        Close(fileout);
  110.  
  111.        {Copy it back}
  112.        Assign(FileIn, doel);
  113.        Reset(FileIn);
  114.        Assign(FileOut, filenaam);
  115.        Rewrite(fileout);
  116.        While not(eof(filein)) do
  117.        Begin
  118.          Readln(filein,s);
  119.          Writeln(fileout,s);
  120.        end;{WHILE}
  121.        Writeln(' --- Rewritten');
  122.        Close(FileOut);
  123.        Close(FileIn);
  124.        Erase(FileIn);
  125.   end{THEN}
  126.   else
  127.   Begin
  128.        Writeln (filenaam:14,'File Not Converted': 25);
  129.        Close(FileIn);
  130.        Close(fileout);
  131.        Erase(fileout);
  132.   end;{ELSE}
  133.  
  134. END; {Herschrijf}
  135.  
  136. Var {Main Progam}
  137.     c_string : string;
  138.     t : byte;
  139.     DirInfo : SearchRec;
  140.     total : integer;
  141.  
  142. begin {Main Program}
  143.   Writeln('ReMove Header --- Version ',version:1:1,' --- Written by C. Enders ---- FREEWARE (1994).');
  144.   Total_Rewritten := 0;
  145.   If paramcount = 0 then
  146.   Begin
  147.     Writeln('Use RMHEADER <Filename> to remove the header of a file.');
  148.     Writeln('Use RMHEADER /? or -? for more info.');
  149.     halt(0)
  150.   end;
  151.   c_string := paramstr(1); {Lees het eerste woord op de commando regel}
  152.   if (c_string = '/?') or (c_string = '-?') then Help;
  153.   ReadConfig;
  154.   total := 0;
  155.   FindFirst(C_string, Archive, DirInfo);
  156.   while DosError = 0 do
  157.   begin
  158.     herschrijf(DirInfo.Name);
  159.     inc(total);
  160.     FindNext(DirInfo);
  161.   end;
  162.   Writeln('Number of files passed    : ', total:6);
  163.   Writeln('Number of files converted : ',Total_Rewritten:6);
  164.  
  165. END. {Program}
  166.